import request from '@/utils/request'
import { download } from '@/utils/request'

// 质量统计 - 合格率统计
export function getQualificationRate(query) {
  return request({
    url: '/qep/dataan/quality/rate',
    method: 'get',
    params: query
  })
}

// 质量统计 - 合格率趋势
export function getQualificationTrend(query) {
  return request({
    url: '/qep/dataan/quality/trend',
    method: 'get',
    params: query
  })
}

// 质量统计 - 合格率对比
export function getQualificationCompare(query) {
  return request({
    url: '/qep/dataan/quality/compare',
    method: 'get',
    params: query
  })
}

// 质量统计 - 缺陷帕累托图
export function getDefectPareto(query) {
  return request({
    url: '/qep/dataan/defect/pareto',
    method: 'get',
    params: query
  })
}

// 质量统计 - 缺陷分布图
export function getDefectDistribution(query) {
  return request({
    url: '/qep/dataan/defect/distribution',
    method: 'get',
    params: query
  })
}

// 质量统计 - TOP缺陷分析
export function getDefectTop(query) {
  return request({
    url: '/qep/dataan/defect/top',
    method: 'get',
    params: query
  })
}

// 质量统计 - 维修率统计
export function getRepairRate(query) {
  return request({
    url: '/qep/dataan/repair/rate',
    method: 'get',
    params: query
  })
}

// 质量统计 - 维修成本分析
export function getRepairCost(query) {
  return request({
    url: '/qep/dataan/repair/cost',
    method: 'get',
    params: query
  })
}

// 质量统计 - 维修效果评估
export function getRepairEvaluation(query) {
  return request({
    url: '/qep/dataan/repair/evaluation',
    method: 'get',
    params: query
  })
}

// SPC分析 - 过程能力
export function getProcessCapability(query) {
  return request({
    url: '/qep/dataan/spc/capability',
    method: 'get',
    params: query
  })
}

// SPC分析 - 控制图
export function getControlChart(query) {
  return request({
    url: '/qep/dataan/spc/controlchart',
    method: 'get',
    params: query
  })
}

// SPC分析 - 趋势分析
export function getSpcTrend(query) {
  return request({
    url: '/qep/dataan/spc/trend',
    method: 'get',
    params: query
  })
}

// 质量追溯 - 产品追溯 (通过ID)
export function getProductTrace(productId) {
  return request({
    url: `/qep/dataan/trace/product/${productId}`,
    method: 'get'
  })
}

// 质量追溯 - 产品追溯 (通过名称)
export function getProductTraceByName(productName) {
  return request({
    url: `/qep/dataan/trace/product/name?productName=${encodeURIComponent(productName)}`,
    method: 'get'
  })
}

// 质量追溯 - 批次追溯 (通过ID)
export function getBatchTrace(batchId) {
  return request({
    url: `/qep/dataan/trace/batch/${batchId}`,
    method: 'get'
  })
}

// 质量追溯 - 批次追溯 (通过批次号)
export function getBatchTraceByNo(batchNo) {
  return request({
    url: `/qep/dataan/trace/batch/no/${encodeURIComponent(batchNo)}`,
    method: 'get'
  })
}

// 质量追溯 - 缺陷追溯 (通过ID)
export function getDefectTrace(defectId) {
  return request({
    url: `/qep/dataan/trace/defect/${defectId}`,
    method: 'get'
  })
}

// 质量追溯 - 缺陷追溯 (通过名称)
export function getDefectTraceByName(defectName) {
  return request({
    url: `/qep/dataan/trace/defect/name/${encodeURIComponent(defectName)}`,
    method: 'get'
  })
}

// 获取所有缺陷名称列表，用于下拉框选择
export function getDefectNameList() {
  return request({
    url: '/qep/dataan/defect/names',
    method: 'get'
  })
}

// 质量追溯 - 导出产品追溯数据
export function exportProductTrace(productName) {
  return download(
    '/qep/dataan/trace/product/export',
    { productName: productName },
    `产品追溯数据_${productName}_${new Date().getTime()}.xlsx`
  )
}

// 质量追溯 - 导出批次追溯数据
export function exportBatchTrace(batchNo) {
  return download(
    '/qep/dataan/trace/batch/export',
    { batchNo: batchNo },
    `批次追溯数据_${batchNo}_${new Date().getTime()}.xlsx`
  )
}

// 质量追溯 - 导出缺陷追溯数据
export function exportDefectTrace(defectName) {
  return download(
    '/qep/dataan/trace/defect/export',
    { defectName: defectName },
    `缺陷追溯数据_${defectName}_${new Date().getTime()}.xlsx`
  )
} 